﻿/****************************************************************************************
 *
 *  Filename:       Form1.cs
 *  Description:    Simple test form for LogSubtPol
 *  License: GPLv2: http://logsubstpol.codeplex.com/license
 *
 *  History
 *  -------
 *
 *    Date   | Author          | Comment
 *  ---------+-----------------+---------------------------------------------------------
 *  08.08.09 | jkalmbach_cp    | First version published on
 *           |                 | Codeplex: http://logsubstpol.codeplex.com/
 *  $log$
 *
 ****************************************************************************************
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace TestApp
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      p.FillCommentInSourceFile(this.textBox1.Text, "c:\\test.cpp", null);
    }


    LogSubstPol.LogSubstPol p = new LogSubstPol.LogSubstPol();
    private void button2_Click(object sender, EventArgs e)
    {
      InitTeamproject();
      p.Edit(new PEA() { TeamProject = tp, Parent = this });
    }

    private void button3_Click(object sender, EventArgs e)
    {
      InitTeamproject();
      polSet = p.Load(tp, polSet);
    }

    LogSubstPol.LogSubstPolSetting polSet;
    TeamProject tp;

    private void button4_Click(object sender, EventArgs e)
    {
      InitTeamproject();
      p.Save(tp);
    }

    void InitTeamproject()
    {
      if (tp == null)
      {
        var tfs = Microsoft.TeamFoundation.Client.TeamFoundationServerFactory.GetServer(this.txtServer.Text);
        VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
        tp = vcs.GetTeamProject(this.txtProject.Text);
      }
    }

    class PEA : IPolicyEditArgs
    {
      public bool IsNew
      {
        get { throw new NotImplementedException(); }
      }

      public IWin32Window Parent {get;set;}

      public TeamProject TeamProject {get;set;}

      public object GetService(Type serviceType)
      {
        throw new NotImplementedException();
      }
    }

    private void button5_Click(object sender, EventArgs e)
    {
      InitTeamproject();
      p.Initialize(new PCI()
      {
        TFS = tp.TeamFoundationServer,
        PendingChanges = new PCPC()
        {
          AllPendingChanges = tp.VersionControlServer.GetWorkspace(Environment.MachineName, tp.VersionControlServer.AuthenticatedUser).GetPendingChanges(),
          Comment = this.textBox1.Text
        }
      });
      p.Evaluate();
    }

      class PCPC : IPendingCheckinPendingChanges
      {
        public string[]  AffectedTeamProjectPaths
        {
	        get { throw new NotImplementedException(); }
        }

        public event AffectedTeamProjectsEventHandler  AffectedTeamProjectsChanged;

        PendingChange[]  _AllPendingChanges;
        public PendingChange[]  AllPendingChanges
        {
	        get { return _AllPendingChanges; }
          set  {  _AllPendingChanges = value;  }
        }

        public PendingChange[]  CheckedPendingChanges
        {
          get 
	        { 
		        return _AllPendingChanges;
	        }
          set { }
        }

        public event EventHandler  CheckedPendingChangesChanged;

        public string  Comment {get; set; }

        #region IPendingCheckinPendingChanges Members


        public Workspace Workspace
        {
          get { throw new NotImplementedException(); }
        }

        #endregion
      }
    class PCI : IPendingCheckin
    {
      public IPendingCheckinPendingChanges PendingChanges {get;set;}

      public Microsoft.TeamFoundation.Client.TeamFoundationServer TFS;
      public object GetService(Type serviceType)
      {
        return TFS.GetService(serviceType);
      }


      #region IPendingCheckin Members

      public IPendingCheckinNotes CheckinNotes
      {
        get { throw new NotImplementedException(); }
      }

      public IPendingCheckinPolicies Policies
      {
        get { throw new NotImplementedException(); }
      }

      public IPendingCheckinWorkItems WorkItems
      {
        get { throw new NotImplementedException(); }
      }

      #endregion
    }
  }
}
